package
{
	public class VectorRenderer
	{
		public var buffer:Container;
		public var thickness:Number;
		public var rgb:Number;
		public var alpha:Number;

		public function VectorRenderer()
		{
			this.buffer = Main.getInstance().gfx.CreateSpriteBuffer(Main.getInstance().gfx.GetNextDepth_Front());
			this.buffer.x = 0;
			this.buffer.y = 0;
			this.thickness = 0;
			this.rgb = 0;
			this.alpha = 100;
		}

		public function Clear():void
		{
			this.buffer.graphics.clear();
			this.buffer.graphics.lineStyle(this.thickness, this.rgb, this.alpha);
		}

		public function SetStyle(thick:Number, rgb:Number, alpha:Number):void
		{
			this.buffer.graphics.lineStyle(thick, rgb, alpha);
		}

		public function StartFill(x:Number, y:Number, rgb:Number, alpha:Number):void
		{
			this.buffer.graphics.moveTo(x, y);
			this.buffer.graphics.beginFill(rgb, alpha);
		}

		public function StopFill():void
		{
			this.buffer.graphics.endFill();
		}

		public function DrawLine(va:Vector2, vb:Vector2):void
		{
			this.buffer.graphics.moveTo(va.x, va.y);
			this.buffer.graphics.lineTo(vb.x, vb.y);
		}

		public function DrawLine_S(x0:Number, y0:Number, x1:Number, y1:Number):void
		{
			this.buffer.graphics.moveTo(x0, y0);
			this.buffer.graphics.lineTo(x1, y1);
		}

		public function DrawLinestrip(vList:Array):void
		{
			this.buffer.graphics.moveTo(vList[0].x, vList[0].y);
			for (var i:int = 0; i < vList.length; i++)
			{
				this.buffer.graphics.lineTo(vList[i].x, vList[i].y);
			}
		}

		public function DrawTri(va:Vector2, vb:Vector2, vc:Vector2):void
		{
			this.buffer.graphics.moveTo(va.x, va.y);
			this.buffer.graphics.lineTo(vb.x, vb.y);
			this.buffer.graphics.lineTo(vc.x, vc.y);
			this.buffer.graphics.lineTo(va.x, va.y);
		}

		public function DrawTri_S(vax:Number, vay:Number, vbx:Number, vby:Number, vcx:Number, vcy:Number):void
		{
			this.buffer.graphics.moveTo(vax, vay);
			this.buffer.graphics.lineTo(vbx, vby);
			this.buffer.graphics.lineTo(vcx, vcy);
			this.buffer.graphics.lineTo(vax, vay);
		}

		public function DrawQuad(a:Vector2, b:Vector2, c:Vector2, d:Vector2):void
		{
			this.buffer.graphics.moveTo(a.x, a.y);
			this.buffer.graphics.lineTo(b.x, b.y);
			this.buffer.graphics.lineTo(c.x, c.y);
			this.buffer.graphics.lineTo(d.x, d.y);
			this.buffer.graphics.lineTo(a.x, a.y);
		}

		public function DrawQuad_S(ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number, dx:Number, dy:Number):void
		{
			this.buffer.graphics.moveTo(ax, ay);
			this.buffer.graphics.lineTo(bx, by);
			this.buffer.graphics.lineTo(cx, cy);
			this.buffer.graphics.lineTo(dx, dy);
			this.buffer.graphics.lineTo(ax, ay);
		}

		public function DrawPlus(v:Vector2):void
		{
			this.buffer.graphics.moveTo(v.x - 1, v.y);
			this.buffer.graphics.lineTo(v.x + 1, v.y);
			this.buffer.graphics.moveTo(v.x, v.y - 1);
			this.buffer.graphics.lineTo(v.x, v.y + 1);
		}

		public function DrawPlus_S(vx:Number, vy:Number):void
		{
			this.buffer.graphics.moveTo(vx - 1, vy);
			this.buffer.graphics.lineTo(vx + 1, vy);
			this.buffer.graphics.moveTo(vx, vy - 1);
			this.buffer.graphics.lineTo(vx, vy + 1);
		}

		public function DrawPlusR(v:Vector2, r:Number):void
		{
			this.buffer.graphics.moveTo(v.x - r, v.y);
			this.buffer.graphics.lineTo(v.x + r, v.y);
			this.buffer.graphics.moveTo(v.x, v.y - r);
			this.buffer.graphics.lineTo(v.x, v.y + r);
		}

		public function DrawCross(v:Vector2):void
		{
			this.buffer.graphics.moveTo(v.x - 1, v.y - 1);
			this.buffer.graphics.lineTo(v.x + 1, v.y + 1);
			this.buffer.graphics.moveTo(v.x + 1, v.y - 1);
			this.buffer.graphics.lineTo(v.x - 1, v.y + 1);
		}

		public function DrawCross_S(vx:Number, vy:Number):void
		{
			this.buffer.graphics.moveTo(vx - 1, vy - 1);
			this.buffer.graphics.lineTo(vx + 1, vy + 1);
			this.buffer.graphics.moveTo(vx + 1, vy - 1);
			this.buffer.graphics.lineTo(vx - 1, vy + 1);
		}

		public function DrawCrossR(v:Vector2, r:Number):void
		{
			this.buffer.graphics.moveTo(v.x - r, v.y - r);
			this.buffer.graphics.lineTo(v.x + r, v.y + r);
			this.buffer.graphics.moveTo(v.x + r, v.y - r);
			this.buffer.graphics.lineTo(v.x - r, v.y + r);
		}

		public function DrawCircle(v:Vector2, r:Number)
		{
			var _local1 = r;
			var _local3 = v.x;
			var _local2 = v.y;
			this.buffer.graphics.moveTo(_local3 + _local1, _local2);
			this.buffer.graphics.curveTo(_local1 + _local3, (0.4142 * _local1) + _local2, (0.7071 * _local1) + _local3, (0.7071 * _local1) + _local2);
			this.buffer.graphics.curveTo((0.4142 * _local1) + _local3, _local1 + _local2, _local3, _local1 + _local2);
			this.buffer.graphics.curveTo((-0.4142 * _local1) + _local3, _local1 + _local2, (-0.7071 * _local1) + _local3, (0.7071 * _local1) + _local2);
			this.buffer.graphics.curveTo((-_local1) + _local3, (0.4142 * _local1) + _local2, (-_local1) + _local3, _local2);
			this.buffer.graphics.curveTo((-_local1) + _local3, (-0.4142 * _local1) + _local2, (-0.7071 * _local1) + _local3, (-0.7071 * _local1) + _local2);
			this.buffer.graphics.curveTo((-0.4142 * _local1) + _local3, (-_local1) + _local2, _local3, (-_local1) + _local2);
			this.buffer.graphics.curveTo((0.4142 * _local1) + _local3, (-_local1) + _local2, (0.7071 * _local1) + _local3, (-0.7071 * _local1) + _local2);
			this.buffer.graphics.curveTo(_local1 + _local3, (-0.4142 * _local1) + _local2, _local1 + _local3, _local2);
		}

		public function DrawCircle_S(x:Number, y:Number, r:Number)
		{
			var _local1 = r;
			var _local2 = y;
			var _local3 = x;
			this.buffer.graphics.moveTo(_local3 + _local1, _local2);
			this.buffer.graphics.curveTo(_local1 + _local3, (0.4142 * _local1) + _local2, (0.7071 * _local1) + _local3, (0.7071 * _local1) + _local2);
			this.buffer.graphics.curveTo((0.4142 * _local1) + _local3, _local1 + _local2, _local3, _local1 + _local2);
			this.buffer.graphics.curveTo((-0.4142 * _local1) + _local3, _local1 + _local2, (-0.7071 * _local1) + _local3, (0.7071 * _local1) + _local2);
			this.buffer.graphics.curveTo((-_local1) + _local3, (0.4142 * _local1) + _local2, (-_local1) + _local3, _local2);
			this.buffer.graphics.curveTo((-_local1) + _local3, (-0.4142 * _local1) + _local2, (-0.7071 * _local1) + _local3, (-0.7071 * _local1) + _local2);
			this.buffer.graphics.curveTo((-0.4142 * _local1) + _local3, (-_local1) + _local2, _local3, (-_local1) + _local2);
			this.buffer.graphics.curveTo((0.4142 * _local1) + _local3, (-_local1) + _local2, (0.7071 * _local1) + _local3, (-0.7071 * _local1) + _local2);
			this.buffer.graphics.curveTo(_local1 + _local3, (-0.4142 * _local1) + _local2, _local1 + _local3, _local2);
		}

		public function DrawArc(p0:Vector2, p1:Vector2, c:Vector2)
		{
			this.buffer.graphics.moveTo(p0.x, p0.y);
			this.buffer.graphics.curveTo(c.x, c.y, p1.x, p1.y);
		}

		public function DrawArc_S(x0:Number, y0:Number, x1:Number, y1:Number, xc:Number, yc:Number)
		{
			this.buffer.graphics.moveTo(x0, y0);
			this.buffer.graphics.curveTo(xc, yc, x1, y1);
		}

		public function DrawAABB(p:Vector2, xw:Number, yw:Number):void
		{
			var _local1 = p;
			var _local2 = xw;
			var _local3 = yw;
			var v0 = new Vector2(_local1.x + _local2, _local1.y + _local3);
			var v1 = new Vector2(_local1.x - _local2, _local1.y + _local3);
			var v2 = new Vector2(_local1.x - _local2, _local1.y - _local3);
			var v3 = new Vector2(_local1.x + _local2, _local1.y - _local3);
			this.DrawQuad(v0, v1, v2, v3);
		}

		public function DrawAABB_S(minx:Number, maxx:Number, miny:Number, maxy:Number)
		{
			var v0 = new Vector2(maxx, maxy);
			var _local3 = new Vector2(minx, maxy);
			var _local2 = new Vector2(minx, miny);
			var _local1 = new Vector2(maxx, miny);
			this.DrawQuad(v0, _local3, _local2, _local1);
		}

		public function DrawConcaveCCWArc_S(cx:Number, cy:Number, px:Number, py:Number)
		{
			var _local1 = cy;
			var _local2 = cx;
			var p0x = px;
			var p0y = py;
			var vx = (p0x - _local2);
			var vy = (p0y - _local1);
			var r = Math.sqrt((vx * vx) + (vy * vy));
			var nx = vy;
			var ny = (-vx);
			var p1x = ((p0x + nx) - _local2);
			var _local3 = (p0y + ny) - _local1;
			var len = Math.sqrt((p1x * p1x) + (_local3 * _local3));
			p1x = p1x / len;
			_local3 = _local3 / len;
			p1x = p1x * r;
			_local3 = _local3 * r;
			p1x = p1x + _local2;
			_local3 = _local3 + _local1;
			var c0x = (((p0x + p1x) * 0.5) - _local2);
			var c0y = (((p0y + _local3) * 0.5) - _local1);
			var clen = Math.sqrt((c0x * c0x) + (c0y * c0y));
			var dlen = (r - clen);
			c0x = c0x / clen;
			c0y = c0y / clen;
			c0x = c0x * (r + dlen);
			c0y = c0y * (r + dlen);
			c0x = c0x + _local2;
			c0y = c0y + _local1;
			this.buffer.graphics.moveTo(p0x, p0y);
			this.buffer.graphics.curveTo(c0x, c0y, p1x, _local3);
			var p0x = p1x;
			var p0y = _local3;
			var vx = (p0x - _local2);
			var vy = (p0y - _local1);
			var r = Math.sqrt((vx * vx) + (vy * vy));
			var nx = vy;
			var ny = (-vx);
			var p1x = ((p0x + nx) - _local2);
			_local3 = (p0y + ny) - _local1;
			var len = Math.sqrt((p1x * p1x) + (_local3 * _local3));
			p1x = p1x / len;
			_local3 = _local3 / len;
			p1x = p1x * r;
			_local3 = _local3 * r;
			p1x = p1x + _local2;
			_local3 = _local3 + _local1;
			var c0x = (((p0x + p1x) * 0.5) - _local2);
			var c0y = (((p0y + _local3) * 0.5) - _local1);
			var clen = Math.sqrt((c0x * c0x) + (c0y * c0y));
			var dlen = (r - clen);
			c0x = c0x / clen;
			c0y = c0y / clen;
			c0x = c0x * (r + dlen);
			c0y = c0y * (r + dlen);
			c0x = c0x + _local2;
			c0y = c0y + _local1;
			this.buffer.graphics.curveTo(c0x, c0y, p1x, _local3);
		}

		public function DrawLinestrip_nrope(vList:Array):void
		{
			this.buffer.graphics.moveTo(vList[0].x, vList[0].y);
			var _local1 = 1;
			while (_local1 < vList.length)
			{
				this.buffer.graphics.lineTo(vList[_local1].x, vList[_local1].y);
				_local1++;
			}
		}
	}
}